/**
 * 
 */
package com.magnusart.scrumppm.model;

import java.util.ArrayList;
import java.util.List;

/**
 * This class assists Project in configuring parameters.
 * Not that client code <b>must</b> to supply a project name,
 * these values also need be at least one character long.
 * @author Magnus Andersson
 *
 */
public final class ProjectBuilder implements Builder
{

	private String name;
	private String description;
	private boolean done;
	private List<Story> children;
	private List<Sprint> sprints;
	
	/**
	 * Default values, the project is not done and 
	 * the name and description is undefined. No children
	 * attached to the project.
	 */
	public ProjectBuilder() {
		name = "";
		description = "";
		done = false;
		children = null;
	}
	
	/**
	 * Create a new project based on a previous
	 * project.
	 * @param project The Project whose data you want to use.
	 */
	public ProjectBuilder( Project project ) {
		name = project.getName();
		description = project.getDescription();
		done = project.isDone();
		children = project.getChildren();
		sprints = project.getSprints();
	}

	/**
	 * This value is mandatory to a project.
	 * @param name The name of this project.
	 */
	public void setName( String name ) {
		this.name = name;
	}
	
	/**
	 * This value is mandatory to a project.
	 * @param description The description of this project.
	 */
	public void setDescription( String description ) {
		this.description = description;		
	}
	
	/**
	 * @param done True for a done down project, false for an open project.
	 */
	public void setDone( boolean done ) {
		this.done = done;		
	}
	
	/**
	 * @param children The children associated with this project.
	 */
	public void setChildern( List<Story> stories ) {
		this.children = stories;
	}
	

	/**
	 * 
	 * @param sprints Set sprints associated with this project.
	 */
	public void setSprints( List<Sprint> sprints ) {
		this.sprints = sprints; 
	}
	
	/**
	 * 
	 * @return Name of the project.
	 */
	String getName() {
		return name;
	}

	/**
	 * 
	 * @return Description of the project.
	 */
	String getDescription() {
		return description;
	}
	
	/**
	 * 
	 * @return Status of this project.
	 */
	boolean isDone() {
		return done;
	}

	/**
	 * A shallow copy of the list is acceptable because the {@link Story} object is immutable.
	 * @return A shallow copy of the list containing associated children.
	 */
	List<Story> getChildren() {
		return ( children != null ) ? new ArrayList<Story>( children ): null ;
	}
	
	/**
	 * Always check this value before using builder on a {@link Project}.
	 * @return The status of this builder. True if complete, false if incomplete.
	 */
	@Override
	public boolean checkStatus() { 
		if( name != null && name.length() > 0 && description != null )
			return true;
		return false;
	}

	List<Sprint> getSprints() {
		return sprints;
	}
}
